<?php
/***************************************************************************
 *   copyright : (C) 2009 Udrea Cristian
 *   site : http://code.google.com/p/testauction-php
 ***************************************************************************/

/***************************************************************************
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as 
 *   published by the Free Software Foundation; either version 2 of the
 *   License, or (at your option) any later version. Although none of the
 *   code may be sold. If you have been sold this script, get a refund.
 ***************************************************************************/
$auction_info = $auctionDB->getAuctionData($_GET['id']);
if (count($auction_info) == 0)
	header("Location: index.php");

$productinfo = $auctionDB->getProductData($auction_info['product_id']);
$offers = $auctionDB->getAuctionLastOffers($auction_info['auction_id']);
$latestoffer = $auctionDB->getAuctionLatestOffer($auction_info['auction_id']);

$PRODUCTNAME = $productinfo['product_name'];
$ACTUALPRICE = $productinfo['shelf_price'];
$PRODUCTDESCRIPTION = $productinfo['description'];

if(!$auction_info['closed']) {
	$min = (integer)$auction_info['time_left'] / 60;
	$sec = $auction_info['time_left'] % 60;

	if($session->logged_in)
		$SOLDOROFFER = "<button class=\"green-button\" 
			onclick=\"putbid('" .$auction_info['auction_id']. "', '" . $session->userid . "', event);\">OFERA</button>";
	else
		$SOLDOROFFER = "<button class=\"green-button\" 
			onclick=\"showHideAlert('Trebuie sa te autentifici mai intai!', event);\">OFERA</button>";
	$BESTBIDDERSTATE = "Ultimul ofertant";
}
else {
	$TIMECOUNTER = "";
	$AUCTIONENDTIME = date("j/n/Y H:i:s", $auction_info['closed_timestamp']);
	$SOLDOROFFER = "<div class=\"orange-button\">VANDUT</div>";
	$BESTBIDDERSTATE = "Cumparator";
}

if ((date('Y',$auction_info['starts_timestamp']) == date('Y', time())) && 
	(date('n',$auction_info['starts_timestamp']) == date('n', time())) &&
	(date('j',$auction_info['starts_timestamp']) == date('j', time()))) {
	
	$AUCTIONSTARTTIME = date("H:i", $auction_info['starts_timestamp']);
}
else {
	$AUCTIONSTARTTIME = date("j/n/Y H:i", $auction_info['starts_timestamp']);
}

$LASTPRICE = $auctionDB->getAuctionOfferCount($auction_info['auction_id'])*$auction_info['offer_increment']+$auction_info['base_price'];
foreach($offers as $item)
	$OFFERLIST .= '<br />' . $item['username'] . ' - ' . $item['date'] . ' - ' . $item['price'];
$BESTBIDDER = $latestoffer['username'];

$PRODUCTIMAGE1 = "produse/" . $productinfo['pict1_url'];
$PRODUCTIMAGE1_THUMB = "produse/thumb_" . $productinfo['pict1_url'];

$PRODUCTIMAGE2 = "produse/" . $productinfo['pict2_url'];
$PRODUCTIMAGE2_THUMB = "produse/thumb_" . $productinfo['pict2_url'];

$PRODUCTIMAGE3 = "produse/" . $productinfo['pict3_url'];
$PRODUCTIMAGE3_THUMB = "produse/thumb_" . $productinfo['pict3_url'];

$PRODUCTIMAGE4 = "produse/" . $productinfo['pict4_url'];
$PRODUCTIMAGE4_THUMB = "produse/thumb_" . $productinfo['pict4_url'];

$contents = "<div id=\"auction_details\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">"
."<tr><td valign=\"top\"><div><div>"
."<span class=\"bold blue\" style=\"font-size: 1.25em;\">".$PRODUCTNAME."</span><br />"
."<span class=\"blue\">Pret in magazine:</span>&nbsp;"
."<span class=\"bold blue\">".$ACTUALPRICE
."&nbsp;CREDITS</span></div><div><br /><br />"
."<span>Pret:</span>&nbsp;"
."<span id=\"lblPrice_".$_GET['id']."\">".$LASTPRICE."</span>"
."<span>&nbsp;CREDITS</span></div><br /><div id=\"auctionTimer\">"
."<span id=\"lblTimer_".$_GET['id']."\" class=\"orange\" style=\"font-size: 1.3em;\">".(($auction_info['closed'])?"Timp ramas:&nbsp":"")."</span>"
."<div id=\"lblTimeCounter_".$_GET['id']."\" style=\"font-size: 1.5em;\"></div>"
."</div><br /><div id=\"auction_button_".$_GET['id']."\">".$SOLDOROFFER."</div><br />"
."<div><span><b class=\"orange\">Ultimele Oferte</b>&nbsp;<br /></span>"
."<span id=\"lblOfferList\" class=\"blue\">".$OFFERLIST."&nbsp;<br/></span>"
."</div><div><br /><br />"
."<span id=\"lblBestBidderState_".$_GET['id']."\" class=\"blue\">".$BESTBIDDERSTATE."</span>&nbsp;<br />"
."<span id=\"lblBestBidder_".$_GET['id']."\" class=\"bold blue\"><b>".$BESTBIDDER."</b></span>"

."<p><span class=\"bold red\" id=\"lblTime_".$_GET['id']."\">"
.(($auction_info['closed']) ? "Incheiata la:&nbsp;<span>".$AUCTIONENDTIME."</span>":"")
.(($auction_info['starts_timestamp'] > time()) ? "<span>".$AUCTIONSTARTTIME."</span>" : "")
."</span></p>"

."<br /><br /></div></div></td><td width=\"400\"><div id=\"product_img\">"
."<img name=\"imgPhoto\" src=\"".$PRODUCTIMAGE1."\" alt=\"".$PRODUCTNAME."\" style=\"border-width:0px;\" /></div>"
."<div id=\"small_pics\">"

."<img id=\"imgSmall1\" width=\"75\" onmouseover=\"imgPhoto.src = '".$PRODUCTIMAGE1."';return false;\" src=\"".$PRODUCTIMAGE1_THUMB."\" "
."alt=\"".$PRODUCTNAME."\" style=\"border-width:0px;\" />"

.(($productinfo['pict2_url'] != "") ?
	"<img id=\"imgSmall2\" width=\"75\" onmouseover=\"imgPhoto.src = '".$PRODUCTIMAGE2."';return false;\" src=\"".$PRODUCTIMAGE2_THUMB."\" 
	alt=\"".$PRODUCTNAME."\" style=\"border-width:0px;\" />" : "")

.(($productinfo['pict3_url'] != "") ?
	"<img id=\"imgSmall3\" width=\"75\" onmouseover=\"imgPhoto.src = '".$PRODUCTIMAGE3."';return false;\" src=\"".$PRODUCTIMAGE3_THUMB."\" 
	alt=\"".$PRODUCTNAME."\" style=\"border-width:0px;\" />" : "")

.(($productinfo['pict4_url'] != "") ?
	"<img id=\"imgSmall4\" width=\"75\" onmouseover=\"imgPhoto.src = '".$PRODUCTIMAGE4."';return false;\" src=\"".$PRODUCTIMAGE4_THUMB."\" 
	alt=\"".$PRODUCTNAME."\" style=\"border-width:0px;\" />" : "")

."<br /><span style=\"font-size: 0.8em;\">".$PRODUCTDESCRIPTION."</span>"
."</div>".$PRODUCT_DESC_TABLE
."</td></tr></table></div>"
."<script type=\"text/javascript\">"
."auction_id_array.push([".$_GET['id'].", ".(($auction_info['starts_timestamp'] < time())?$min:0).", ".(($auction_info['starts_timestamp'] < time())?$sec:0).", 0]); refreshItems(2, ".$_GET['id']."); countDown();"
."</script>";

$template->setCurrentBlock("table_page");
$template->setVariable(TABLEPAGECONTENT, $contents);
$template->parseCurrentBlock();
?>
